package com.xinziruo.crawl.infrastruture.support.server;

import org.apache.mina.core.session.IoSession;

import com.xinziruo.crawl.infrastruture.support.command.Command;

/**
 * 
 * @author loudyn
 * 
 */
public class CommandClient {
	private final IoSession session;
	private long heartbeatTime;

	public CommandClient(IoSession session) {
		this.session = session;
	}

	/**
	 * 
	 * @return
	 */
	public IoSession getSession() {
		return session;
	}

	/**
	 * 
	 * @param command
	 */
	public void writeCommand(Command command) {
		session.write(command);
	}

	/**
	 * 
	 * @return
	 */
	public CommandClient updateHeartbeat() {
		this.heartbeatTime = System.currentTimeMillis();
		return this;
	}

	public boolean isLoseHeartbeat() {
		long current = System.currentTimeMillis();
		return (current - heartbeatTime) >= 180 * 1000;
	}

}
